﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace MailMerge_Generator
{
    [Serializable]
    public class LetterObject
    {
        //I want to include the option to set the basic formatting of each paragraph.
        //To do this efficiently, I have created a subclass paragraph.
        public class paragraph
        {
            public String text;
            public String bookmark;
            public Boolean exists;
            public Boolean hasMark;
            //should be ints for the formatting stuff
            public int SpaceAbove;
            public int SpaceBelow;
            public int LeftIndent;
            public int FirstLine;
            public paragraph()
            {
                text = "";
                bookmark = "";
                exists = true;
                hasMark = false;
                SpaceAbove = 0;
                SpaceBelow = 0;
                LeftIndent = 0;
                FirstLine = 0;
            }
            public paragraph(String t, String b, Boolean e, Boolean m, int sa, int sb, int li, int fli)
            {
                text = t;
                bookmark = b;
                exists = e;
                hasMark = m;
                SpaceAbove = sa;
                SpaceBelow = sb;
                LeftIndent = li;
                FirstLine = fli;
            }
            //method to clean up
            public void clean()
            {
                text = "";
                bookmark = "";
                exists = true;
                hasMark = false;
                SpaceAbove = 0;
                SpaceBelow = 0;
                LeftIndent = 0;
                FirstLine = 0;
            }
        }
        //Letter parts
        public paragraph Greeting = new paragraph("","",true,false,0,6,0,0);
        public paragraph Body = new paragraph("", "", true, false, 0, 6, 0, 36);
        public paragraph Summary = new paragraph("", "", true, false, 12, 0, 72, 0);
        public paragraph Closing = new paragraph("", "", true, false, 0, 18, 216, 0);
        public paragraph Sender = new paragraph("", "", true, false, 0, 0, 216, 0);
        //File Paths
        public String MergeFilePath = "";
        public String TableFilePath = "";
        public String TemplateFilePath = "";
        //Keys and Headers
        public String MergeSource = "";
        public String TableSource = "";
        public String TableKey = "";
        public String MergeKey = "";
        //Bookmark Strings
        public String bk_Table = "";
        //Lists of fields
        public List<String> MergeFields = new List<string>();
        public List<String> TableFields = new List<string>();
        //Booleans
        public Boolean HasTemplate = false;
        public Boolean HasMerge = true;
        public Boolean HasTable = true;
        public Boolean bk_HasTable = false;
        public void Clear()
        {
            Greeting.clean();
            Body.clean();
            Summary.clean();
            Closing.clean();
            Sender.clean();
            TableFilePath = "";
            MergeFilePath = "";
            MergeSource = "";
            TableSource = "";
            TableKey = "";
            MergeKey = "";
            MergeFields.Clear();
            TableFields.Clear();
            HasTemplate = false;
            HasMerge = true;
            HasTable = true;
            //Everything is reset.
        }
        public String Mergefilename()
        {
            int start = MergeFilePath.LastIndexOf('\\');
            if (start == -1)
            {
                return "the mail merge table.";
            }
            else
            {                
                String filename = MergeFilePath.Substring(start+1);
                return filename;
            }
        }
        public String Tablefilename()
        {
            int start = TableFilePath.LastIndexOf('\\');
            if (start == -1)
            {
                return "the royalty table.";
            }
            else
            {
                String filename = TableFilePath.Substring(start+1);
                return filename;
            }
        }
    }
}
